<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

   

    <input class="user" type="text">
    <br>
    <input class="pwd" type="text">
    <br>
    <button>注册</button>


    <script>

        const oBtn = document.querySelector('button') ;
        const oUser = document.querySelector('.user') ;
        const oPwd = document.querySelector('.pwd') ;

        


        oBtn.onclick = function() {
            // 获取用户名和密码
            const user = oUser.value ;
            const pwd = oPwd.value ;

            // 判断用户名是否存在
            let res = localStorage.getItem('YYDS_' + user) ;
            if(res) {
                alert('用户名已被注册') ;
            } else {
                // 去注册
                localStorage.setItem('YYDS_' + user , pwd) ;
            }

        }

    </script>
    
</body>
</html>